﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using WRJClient.UI.Map;
using WRJClient.ViewModel;
using Esri.ArcGISRuntime.Geometry;

namespace WRJClient.UI.SystemMonitor
{
    /// <summary>
    /// UavView.xaml 的交互逻辑
    /// </summary>
    public partial class UavView : UserControl
    {
        public UavView(UAVViewModel model)
        {
            InitializeComponent();
            MapManager.Instance.Init(baseMap);

            body.DataContext = model;

            model.PropertyChanged += Model_PropertyChanged;

            model.AddGraphics();
        }

        private void Model_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            UAVViewModel model = sender as UAVViewModel;
            if (model != null && model.Telemetry != null && baseMap.mapView.Map != null)
            {
                if (baseMap.mapView.MapScale == baseMap.mapView.Map.MinScale)
                {
                    baseMap.PanTo(new MapPoint(model.Telemetry.Longitude, model.Telemetry.Latitude, SpatialReferences.Wgs84), 5000);
                }
                else
                {
                    baseMap.PanTo(new MapPoint(model.Telemetry.Longitude, model.Telemetry.Latitude, SpatialReferences.Wgs84));
                }
            }
        }
    }
}
